home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / KoDom.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-30  |  2.5 KB  |  71 lines

  1. /* This file is part of the KDE project
  2.    Copyright (C) 2004 David Faure <faure@kde.org>
  3.  
  4.    This library is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License as published by the Free Software Foundation; either
  7.    version 2 of the License, or (at your option) any later version.
  8.  
  9.    This library is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.    Library General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU Library General Public License
  15.    along with this library; see the file COPYING.LIB.  If not, write to
  16.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.  * Boston, MA 02110-1301, USA.
  18. */
  19.  
  20. #ifndef KODOM_H
  21. #define KODOM_H
  22.  
  23. #include <qdom.h>
  24. #include <koffice_export.h>
  25. /**
  26.  * This namespace contains a few convenience functions to simplify code using QDom
  27.  * (when loading OASIS documents, in particular).
  28.  *
  29.  * To find the child element with a given name, use KoDom::namedItemNS.
  30.  *
  31.  * To find all child elements with a given name, use
  32.  * QDomElement e;
  33.  * forEachElement( e, parent )
  34.  * {
  35.  *     if ( e.localName() == "..." && e.namespaceURI() == KoXmlNS::... )
  36.  *     {
  37.  *         ...
  38.  *     }
  39.  * }
  40.  * Note that this means you don't ever need to use QDomNode nor toElement anymore!
  41.  * Also note that localName is the part without the prefix, this is the whole point
  42.  * of namespace-aware methods.
  43.  *
  44.  * To find the attribute with a given name, use QDomElement::attributeNS.
  45.  *
  46.  * Do not use getElementsByTagNameNS, it's recursive (which is never needed in KOffice).
  47.  * Do not use tagName() or nodeName() or prefix(), since the prefix isn't fixed.
  48.  *
  49.  * @author David Faure <faure@kde.org>
  50.  */
  51. namespace KoDom {
  52.  
  53.     /**
  54.      * A namespace-aware version of QDomNode::namedItem(),
  55.      * which also takes care of casting to a QDomElement.
  56.      * Use this when a domelement is known to have only *one* child element
  57.      * with a given tagname.
  58.      *
  59.      * Note: do *NOT* use getElementsByTagNameNS, it's recursive!
  60.      */
  61.     KOFFICECORE_EXPORT QDomElement namedItemNS( const QDomNode& node, const char* nsURI, const char* localName );
  62.  
  63. }
  64.  
  65. #define forEachElement( elem, parent ) \
  66.       for ( QDomNode _node = parent.firstChild(); !_node.isNull(); _node = _node.nextSibling() ) \
  67.         if ( !( elem = _node.toElement() ).isNull() )
  68.  
  69. #endif /* KODOM_H */
  70.  
  71.